//
//  DsErYiCell.m
//  Tour
//
//  Created by 张张烨 on 16/3/9.
//  Copyright © 2016年 张中烨. All rights reserved.
//

#import "DsErYiCell.h"
#define WIDTH1 self.contentView.frame.size.width
#define HEIGHT self.contentView.frame.size.height
@interface DsErYiCell ()
@property (nonatomic, retain)UILabel *name;             //  名字
@property (nonatomic, retain)UILabel *start_date;       // 时间
@property (nonatomic, retain)UILabel *views_count;      // 查看人数;
@property (nonatomic,retain) UILabel *comments_count;   // 评论
@property (nonatomic,retain) UILabel *likes_count;      // 喜欢人数
@property (nonatomic, retain)UIImageView *tupian; //图片
@property (nonatomic, retain)UIImageView *image;        // 用户头像
@property (nonatomic, retain) UILabel *username;        // 用户名
@end

@implementation DsErYiCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.clipsToBounds = YES;
        
        self.contentView.userInteractionEnabled = YES;
        // 图片
        self.tupian = [[UIImageView alloc]initWithFrame:CGRectMake(0, -(HEIGH/1.7 -(250 * GAO))/2, WIDTH, HEIGH/1.7)];
        _tupian.contentMode = UIViewContentModeScaleAspectFill;
        [self.contentView addSubview:_tupian];
       
        
        // 标题名字
        self.name = [[UILabel alloc]init];
        _name.textColor =[UIColor colorWithRed:255/250 green:255/250 blue:255/250 alpha:1];
        _name.font = [UIFont systemFontOfSize:20];
        _name.numberOfLines = 0;
        [self.contentView addSubview:_name];
      
        
        // 时间
        self.start_date = [[UILabel alloc]init];
        _start_date.textColor = [UIColor whiteColor];
        _start_date.font = [UIFont systemFontOfSize:16];
        [self.contentView addSubview:_start_date];
     
        
//        // 查看人数;
//        self.views_count= [[UILabel alloc]init];
//        [self.contentView addSubview:_views_count];
//        _views_count.font = [UIFont systemFontOfSize:10];
       
        
        
//        // 评论
//        self.comments_count = [[UILabel alloc]init];
//        _comments_count.font = [UIFont systemFontOfSize:10];
//        [self.contentView addSubview:_comments_count];
       
        
//        // 喜欢人数
//        self.likes_count = [[UILabel alloc]init];
//        _likes_count.font = [UIFont systemFontOfSize:10];
//        [self.contentView addSubview:_likes_count];
       
        
//        // 用户名
//        self.username = [[UILabel alloc]init];
//        _username.font = [UIFont systemFontOfSize:15];
//        _username.textColor = [UIColor whiteColor];
//        [self.contentView addSubview:_username];
      
        
        
        // 用户头像
        self.image = [[UIImageView alloc]init];
        _image.layer.borderColor = [[UIColor whiteColor] CGColor];
        _image.layer.borderWidth = 3.0f;
        
        _image.userInteractionEnabled = YES;
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap)];
        [_image addGestureRecognizer:tap];

        [self.contentView addSubview:_image];
       
        
        
    }
    return self;
}

/**<  给头像加轻拍手势 */
- (void)tap
{
    [self.delagate passtiaotiao:_model.userid];
}



-(void)setModel:(DsErYiModel *)model
{
    _model = model;
    
    // 大图片
    [self.image sd_setImageWithURL:[NSURL URLWithString:_model.image]];
    
    [self.tupian sd_setImageWithURL:[NSURL URLWithString:_model.front_cover_photo_url]];
    // 用户头像
    self.name.text = [NSString stringWithFormat:@"         %@",_model.name];                    // 标题名
    self.username.text = _model.username;            // 用户名
    self.start_date.text = _model.start_date;        // 时间
    self.views_count.text = [_model.views_count stringValue];       // 查看人数
    self.comments_count.text = [_model.comments_count stringValue]; // 评论数
    self.likes_count.text = [_model.likes_count stringValue];
    
}
/**<  给图片加动态图 */
- (CGFloat)cellOffset {
    
    
    CGRect centerToWindow = [self convertRect:self.bounds toView:self.window];
    CGFloat centerY = CGRectGetMidY(centerToWindow);
    CGPoint windowCenter = self.superview.center;
    
    CGFloat cellOffsetY = centerY - windowCenter.y;
    
    CGFloat offsetDig =  cellOffsetY / self.superview.frame.size.height *2;
    CGFloat offset =  -offsetDig * (667/1.7 - 250)/2;
    
    CGAffineTransform transY = CGAffineTransformMakeTranslation(0,offset);
    self.tupian.transform = transY;
    
    return offset;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
   
    _image.frame = CGRectMake(20 * KUAN, HEIGHT - (60 * GAO), 40, 40);

    // 标题
    _name.frame = CGRectMake(20 * KUAN, 20 * GAO, WIDTH1-30, 60 * GAO);
    _username.frame = CGRectMake(_image.frame.origin.x + 50 + 10, HEIGHT - 50 + 5 , WIDTH1 - 90, 20);// 用户名
    _start_date.frame =  CGRectMake(20, 80, 200, 20);                       // 时间
    _views_count.frame = CGRectMake(60, HEIGHT - 15, 100, 10);              // 查看人数
    _comments_count.frame = CGRectMake(WIDTH1 - 90, HEIGHT- 15, 30, 10);     // 评论数
    _likes_count.frame = CGRectMake(WIDTH1 - 30, HEIGHT - 15, 30, 10);       // 喜欢人数/ 点赞数
    
    
    //img 查看人数
    UIImageView *viewimg = [[UIImageView alloc]initWithFrame:CGRectMake(30, HEIGHT - 20, 20, 20)];
    viewimg.image = [UIImage imageNamed:@"iconfont-chakan"];
    [self.contentView addSubview:viewimg];
    
    
    //img 评论数
    UIImageView *commimg = [[UIImageView alloc]initWithFrame:CGRectMake(WIDTH1 - 120, HEIGHT - 20, 20, 20)];
    commimg.image = [UIImage imageNamed:@"iconfont-pinglun"];
    [self.contentView addSubview:commimg];
   
    
    // img 喜欢人数
    UIImageView *likeimg = [[UIImageView alloc]initWithFrame:CGRectMake(WIDTH1 - 60, HEIGHT - 20, 20, 20)];
    likeimg.image = [UIImage imageNamed:@"iconfont-like"];
    [self.contentView addSubview:likeimg];


}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
